<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生成绩查询</title>
</head>
<body>
<div id="app">
    <el-container style="height: 720px; border: 1px solid #eee">
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
            <el-menu @open="handleOpen">
                <el-submenu index="1">
                    <template slot="title">
                        <i class="el-icon-menu"></i>首页
                    </template>
                </el-submenu>

                <el-submenu index="2">
                    <template slot="title"><i class="el-icon-s-custom"></i>个人信息</template>
                    <el-menu-item-group>
                        <el-menu-item @click="addInfo">完善个人信息</el-menu-item>
                        <el-menu-item @click="lookInfo">查看个人信息</el-menu-item>
                    </el-menu-item-group>
                </el-submenu>

                <el-submenu index="3">
                    <template slot="title"><i class="el-icon-setting"></i>账号设置</template>
                    <el-menu-item-group>
                        <el-menu-item @click="exitAccount">退出账号</el-menu-item>
                        <el-menu-item @click="destroyAccount">注销账号</el-menu-item>
                    </el-menu-item-group>
                </el-submenu>
            </el-menu>
        </el-aside>

        <el-container>
            <el-main>
                <iframe
                        :src="iframeUrl"
                        width="100%"
                        height="670px"
                        style="border: medium none;"
                        frameborder="0"
                        scrolling="auto"
                >
                </iframe>
            </el-main>
        </el-container>
    </el-container>
</div>

<script src="../js/vue.js"></script>
<script src="../element-ui/lib/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<link rel="stylesheet" href="../element-ui/lib/theme-chalk/index.css">

<script>
    new Vue({
        el:"#app",
        data(){
            return{
                iframeUrl:'../component/StudentTable.html'
            }
        },
        methods:{
            handleOpen(key) {
                if(key==1){
                    this.iframeUrl='../component/StudentTable.html';
                }
            },
            addInfo(){
                axios({
                    method:'get',
                    url:"http://localhost:8080/addInfo/getInfo",
                    headers:{
                        'Authorization':localStorage.getItem('token')
                    }
                }).then(result=>{
                    if(result.data.code==1){
                        this.iframeUrl='../component/AddPersonInfo.html';
                    }else if(result.data.code==0){
                        this.iframeUrl='../component/AddInfoSuccess.html';
                    }
                })
            },
            lookInfo(){
                this.iframeUrl='../component/LookPersonInfo.html';
            },
            exitAccount(){
                axios({
                    method:'get',
                    url:"http://localhost:8080/accounts/exitAccount",
                    headers:{
                        'Authorization':localStorage.getItem('token')
                    }
                }).then(result=>{
                        if(result.data.code==1){
                            this.$message({
                                type: 'success',
                                message: '账号已退出!'
                            });
                            location.href="Login.html";
                        }
                     })
            },
            destroyAccount(){
                this.$confirm('确认注销此账号?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        method:'delete',
                        url:"http://localhost:8080/accounts/destroyAccount",
                        headers:{
                            'Authorization':localStorage.getItem('token')
                        }
                    }).then(result=>{
                        if(result.data.code==1){
                            this.$message({
                                type: 'success',
                                message: '账号已注销!'
                            });
                            location.href="Login.html";
                        }
                     })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })

</script>
</body>
</html>